package org.example.config;

import org.example.interceptor.ApiSecurityInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Description:
 * WebMvcConfigurerAdapter 抽象类是对WebMvcConfigurer接口的简单抽象（增加了一些默认实现），
 * 但在在SpringBoot2.0及Spring5.0中WebMvcConfigurerAdapter已被废弃 。
 * 官方推荐直接实现WebMvcConfigurer或者直接继承WebMvcConfigurationSupport
 * @author shenguangyang
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Bean
    public ApiSecurityInterceptor apiSecurityInterceptor() {
       return new ApiSecurityInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //多个拦截器会按照顺序进行校验拦截  内部维护了一个list集合 registrations
        //private final List<InterceptorRegistration> registrations = new ArrayList<>();
        registry.addInterceptor(apiSecurityInterceptor());
        //registry.addInterceptor(new CheckPermissionHandler());
    }
}
